package cn.itrip.biz.controller;

import cn.itrip.beans.dto.Dto;
import cn.itrip.beans.pojo.ItripAreaDic;
import cn.itrip.beans.pojo.ItripLabelDic;
import cn.itrip.beans.vo.ItripAreaDicVO;
import cn.itrip.beans.vo.ItripImageVO;
import cn.itrip.beans.vo.ItripLabelDicVO;
import cn.itrip.beans.vo.hotel.HotelVideoDescVO;
import cn.itrip.beans.vo.hotel.ItripSearchDetailsHotelVO;
import cn.itrip.beans.vo.hotel.ItripSearchFacilitiesHotelVO;
import cn.itrip.beans.vo.hotel.ItripSearchPolicyHotelVO;
import cn.itrip.biz.service.ItripAreaDicService;
import cn.itrip.biz.service.ItripHotelService;
import cn.itrip.biz.service.ItripImageService;
import cn.itrip.biz.service.ItripLabelDicService;
import cn.itrip.common.DtoUtil;
import cn.itrip.common.EmptyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Api(value = "API", basePath = "/http://api.itrap.com/api")
@RequestMapping(value = "/api/hotel")
public class HotelController {

    @Resource
    private ItripAreaDicService itripAreaDicService;

    @Resource
    private ItripLabelDicService itripLabelDicService;

    @Resource
    private ItripHotelService itripHotelService;

    @Resource
    private ItripImageService itripImageService;

    /**
     * 查询酒店热门城市
     * @param type
     * @return
     */

    @ApiOperation(value = "查询热门城市", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "查询国内、国外的热门城市(1:国内 2:国外)" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>10201 : hotelId不能为空 </p>" +
            "<p>10202 : 系统异常,获取失败</p>")
    @ResponseBody
    @RequestMapping(value = "/queryhotcity/{type}", method = RequestMethod.GET, produces = "application/json")
    public Dto<ItripAreaDicVO> queryHotCity(@PathVariable Integer type) {
        List<ItripAreaDic> itripAreaDicS = null;
        List<ItripAreaDicVO> itripAreaDicVOS = null;
        try {
            if (EmptyUtils.isNotEmpty(type)) {
                Map<String, Object> citys = new HashMap<>();
                citys.put("isHot", 1);
                citys.put("isChina", type);
                itripAreaDicS = itripAreaDicService.getItripAreaDicListByMap(citys);
                itripAreaDicVOS = new ArrayList<>();
                if (EmptyUtils.isNotEmpty(itripAreaDicS)) {
                    for (ItripAreaDic itripAreaDic : itripAreaDicS) {
                        ItripAreaDicVO dicVO = new ItripAreaDicVO();
                        BeanUtils.copyProperties(itripAreaDic,dicVO);
                        itripAreaDicVOS.add(dicVO);
                    }
                }
            } else {
                DtoUtil.returnFail("type类型不能为空", "10201");
            }

        } catch (Exception e) {
            DtoUtil.returnFail("系统异常", "10202");
            e.printStackTrace();
        }
        return DtoUtil.returnDataSuccess(itripAreaDicVOS);
    }

    /**
     * 查询商圈的接口(@param cityId 根据城市查询商圈)
     * @param cityId
     * @return
     */
    @ApiOperation(value = "查询商圈", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据城市查询商圈" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>10203 : cityId不能为空 </p>" +
            "<p>10204 : 系统异常,获取失败</p>")
    @ResponseBody
    @RequestMapping(value = "/querytradearea/{cityId}",
            produces = "application/json", method = RequestMethod.GET)
    public Dto<ItripAreaDicVO> queryTradeArea(@PathVariable Long cityId){
        List<ItripAreaDic> itripAreaDicS = null;
        List<ItripAreaDicVO> itripAreaDicVOS = null;
        try {
            if (EmptyUtils.isNotEmpty(cityId)) {
                Map<String, Object> citys = new HashMap<>();
                citys.put("isTradingArea", 1);
                citys.put("parent", cityId);
                itripAreaDicS = itripAreaDicService.getItripAreaDicListByMap(citys);
                if (EmptyUtils.isNotEmpty(itripAreaDicS)) {
                    for (ItripAreaDic itripAreaDic : itripAreaDicS) {
                        ItripAreaDicVO dicVO = new ItripAreaDicVO();
                        BeanUtils.copyProperties(itripAreaDic,dicVO);
                        itripAreaDicVOS.add(dicVO);
                    }
                }
            } else {
                DtoUtil.returnFail("cityID不能为空", "10203");
            }

        } catch (Exception e) {
            DtoUtil.returnFail("系统异常", "10204");
            e.printStackTrace();
        }
        return DtoUtil.returnDataSuccess(itripAreaDicVOS);
    }

    /**
     * 查询酒店特色列表接口
     * @return
     */
    @ApiOperation(value = "查询酒店特色列表", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "获取酒店特色(用于查询页列表)" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码: </p>" +
            "<p>10205: 系统异常,获取失败</p>")

    @RequestMapping(value = "/queryhotelfeature", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto<ItripLabelDicVO> queryHotelFeature(){
    List<ItripLabelDic> labelDics = null;
        List<ItripLabelDicVO> labelDicVOS = null;
        try {
                Map<String, Object> feature = new HashMap<>();
                feature.put("parentId", 16);
                 labelDics = itripLabelDicService.getItripLabelDicListByMap(feature);
            labelDicVOS=new ArrayList<ItripLabelDicVO>();
                if (EmptyUtils.isNotEmpty(labelDics)) {
                    for (ItripLabelDic itripLabelDic : labelDics) {
                        ItripLabelDicVO dicVO = new ItripLabelDicVO();
                        BeanUtils.copyProperties(itripLabelDic,dicVO);
                        labelDicVOS.add(dicVO);
                    }
                }
        } catch (Exception e) {
            DtoUtil.returnFail("系统异常", "10205");
            e.printStackTrace();
        }
        return DtoUtil.returnDataSuccess(labelDicVOS);
    }

    /**
     * 根据酒店ID查询酒店设施接口
     * @return
     */
    @ApiOperation(value = "根据酒店id查询酒店设施", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据酒店id查询酒店设施" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>10206: 酒店id不能为空</p>" +
            "<p>10207: 系统异常,获取失败</p>")
    @RequestMapping(value = "/queryhotelfacilities/{id}", produces = "application/json",
            method = RequestMethod.GET)
    @ResponseBody
    public Dto<ItripSearchFacilitiesHotelVO> queryHotelFacilities(@PathVariable Long id){
        ItripSearchFacilitiesHotelVO itripSearchFacilitiesHotelVO = null;
        try {
            if(EmptyUtils.isNotEmpty(id)){
                itripSearchFacilitiesHotelVO=itripHotelService.getItripHotelFacilitiesById(id);
                return DtoUtil.returnDataSuccess(itripSearchFacilitiesHotelVO.getFacilities());
            }else{
               return DtoUtil.returnFail("hotelID不能为空","10206");
            }
        } catch (Exception e) {
            e.printStackTrace();
           return DtoUtil.returnFail("系统异常,获取失败", "10207");
        }

    }

    /**
     * 根据酒店ID查询酒店政策
     * @return
     */
    @ApiOperation(value = "根据酒店id查询酒店政策", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据酒店id查询酒店政策" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>10208: 酒店id不能为空</p>" +
            "<p>10209: 系统异常,获取失败</p>")
    @RequestMapping(value = "/queryhotelpolicy/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto<ItripSearchFacilitiesHotelVO> queryHotelPolicy(@PathVariable long id){
        ItripSearchPolicyHotelVO itripSearchPolicyHotelVO = null;
        try {
            if (EmptyUtils.isNotEmpty(id)) {
                itripSearchPolicyHotelVO = itripHotelService.queryHotelPolicy(id);
                return DtoUtil.returnDataSuccess(itripSearchPolicyHotelVO.getHotelPolicy());
            } else {
                return DtoUtil.returnFail("酒店id不能为空", "10208");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10209");
        }
    }

    /**
     * 根据酒店ID查询酒店特色和介绍
     * @return
     */
    @ApiOperation(value = "根据酒店id查询酒店特色和介绍", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据酒店id查询酒店特色和介绍" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>10210: 酒店id不能为空</p>" +
            "<p>10211: 系统异常,获取失败</p>")
    @RequestMapping(value = "/queryhoteldetails/{id}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto<ItripSearchFacilitiesHotelVO> queryHotelDetails(@PathVariable long id){
       List<ItripSearchDetailsHotelVO> itripSearchDetailsHotelVO = null;
        try {
            if (EmptyUtils.isNotEmpty(id)) {
                itripSearchDetailsHotelVO =itripHotelService.queryHotelDetails(id);
                return DtoUtil.returnDataSuccess(itripSearchDetailsHotelVO);
            } else {
                return DtoUtil.returnFail("酒店id不能为空", "10210");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常,获取失败", "10211");
        }

    }

    @ApiOperation(value = "根据targetId查询酒店图片(type=0)", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据酒店ID查询酒店图片" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>100212 : 获取酒店图片失败 </p>" +
            "<p>100213 : 酒店id不能为空</p>")
    @RequestMapping(value = "/getimg/{targetId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto<Object> getImgByTargetId(@PathVariable String targetId){
        List<ItripImageVO> itripImageVOS = null;
        try {
            if (EmptyUtils.isNotEmpty(targetId)) {
                Map<String,Object>imgs=new HashMap<>();
                imgs.put("type", "0");
                imgs.put("targetId", targetId);
                itripImageVOS =itripImageService.getItripImageListByMap(imgs);
                return DtoUtil.returnSuccess("获取酒店图片成功",itripImageVOS);
            } else {
                return DtoUtil.returnFail("酒店id不能为空", "100213");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("获取酒店图片成功", "100212");
        }
    }

    @ApiOperation(value = "根据酒店id查询酒店特色、商圈、酒店名称", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据酒店id查询酒店特色、商圈、酒店名称（视频文字描述）" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>100214 : 获取酒店视频文字描述失败 </p>" +
            "<p>100215 : 酒店id不能为空</p>")
    @RequestMapping(value = "/getvideodesc/{hotelId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto<Object> getVideoDescByHotelId(@PathVariable String hotelId){
        Dto<Object> dto = new Dto<Object>();
        if (null != hotelId && !"".equals(hotelId)) {
            HotelVideoDescVO hotelVideoDescVO = null;
            try {
                hotelVideoDescVO = itripHotelService.getVideoDescByHotelId(Long.valueOf(hotelId));
                dto = DtoUtil.returnSuccess("获取酒店视频文字描述成功", hotelVideoDescVO);
            } catch (Exception e) {
                e.printStackTrace();
                dto = DtoUtil.returnFail("获取酒店视频文字描述失败", "100214");
            }

        } else {
            dto = DtoUtil.returnFail("酒店id不能为空", "100215");
        }
        return dto;
    }
}
